package com.gx.telephonedemo2.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.gx.telephonedemo2.R;

import java.util.ArrayList;
import java.util.Map;

/**
 * Description:录音列表
 * Author: GX
 * CreateDate: 2019/8/2 13:29
 * UpdateUser: GX
 * UpdateDate: 2019/8/2 13:29
 * UpdateRemark:
 * Version: 1.0
 */
public class RecordAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<Map<String, String>> mData;
    PlayClickListener mClickListener;

    public RecordAdapter(Context context, ArrayList<Map<String, String>> strings, PlayClickListener clickListener) {
        this.mContext = context;
        this.mData = strings;
        this.mClickListener = clickListener;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View convertView, ViewGroup viewGroup) {
        View view = convertView;

        if (view == null) {
            //因为getView()返回的对象，adapter会自动赋给ListView
            view = LayoutInflater.from(mContext).inflate(R.layout.listview_item_record, null);
        }
        TextView tvNum = view.findViewById(R.id.tvNum);//找到Textviewname
        tvNum.setText(mData.get(i).get("name"));//设置参数
        view.setOnClickListener(view1 -> mClickListener.clickPlay(mData.get(i).get("name")));
        return view;
    }

    public interface PlayClickListener {
        void clickPlay(String path);
    }
}
